<?php
/**
 * The following variables are available in this template:
 * - $this: the CrudCode object
 */
?>
<?php echo "<?php\n"; ?>
/* @var $this <?php echo $this->getControllerClass(); ?> */
/* @var $model <?php echo $this->getModelClass(); ?> */
/* @var $form CActiveForm */
?>

<div class="form">
	
	<?php
	foreach ($this->tableSchema->columns as $column) {
		if ($column->autoIncrement) {
			continue;
		}
		$focus = $column->name;
		break;
	}
	echo "<?php\n";
	echo "\t\$properties = array(
		'id'=>'" . $this->class2id($this->modelClass) . "-form',
		'enableAjaxValidation'=>false,
		'focus'=>array(\$model, '$focus'),
	);\n";
	echo "\t\$form = \$this->beginWidget('CActiveForm', \$properties);\n";
	echo "\t?>\n"
	?>

	<p class="note">
		Fields with <span class="required">*</span> are required.
	</p>

	<?php echo "<?php echo \$form->errorSummary(\$model); ?>\n"; ?>

<?php
	foreach ($this->tableSchema->columns as $column):
		if ($column->autoIncrement) {
			continue;
		}
?>
	<div class="row">
		<?php
		echo "<?php\n";
		echo $this->generateActiveLabel($this->modelClass, $column) . "\n";
		echo $this->generateActiveField($this->modelClass, $column) . "\n";
		echo "\t\techo \$form->error(\$model, '{$column->name}');\n";
		echo "\t\t?>\n";
		?>
	</div>

<?php endforeach; ?>
	<div class="row buttons">
		<?php
		echo "<?php\n";
		echo "\t\t\$label = \$model->isNewRecord ? 'Create' : 'Save';\n";
		echo "\t\techo CHtml::submitButton(\$label);\n";
		echo "\t\t?>\n"
		?>
	</div>
	
	<?php echo "<?php \$this->endWidget(); ?>\n"; ?>

</div><!-- form -->